Skip to content

Add optional commit SHA in config.#93

Open
jefchien wants to merge 1 commit into
benchmark-action:masterfrom
jefchien:add-optional-commit-sha
Open

Add optional commit SHA in config.#93
jefchien wants to merge 1 commit into
benchmark-action:masterfrom
jefchien:add-optional-commit-sha

Conversation

@jefchien

Copy link
Copy Markdown

Description

Allows the user to pass in a commit SHA to use instead of relying on the payload or head commit. The main use-case of this is for workflow dispatch runs where the SHA is provided through an input.

This change should be valid based on https://docs.github.com/en/rest/reference/commits#get-a-commit.

@jefchien jefchien force-pushed the add-optional-commit-sha branch from 4ab55a4 to 35c0db2 Compare December 17, 2021 21:25
Comment thread src/extract.ts

async function getCommit(githubToken?: string): Promise<Commit> {
async function getCommit(githubToken?: string, commitSha?: string): Promise<Commit> {
if (commitSha && githubToken) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this line be placed after the line 253-261 ? Mostly I can't see any reason to let this success faster though.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, if you've provided the commit SHA, then your intention is for the action to use it. I don't see why it should even attempt to use the other options.

@khanhntd khanhntd left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@ktrz

ktrz commented Dec 21, 2021

Copy link
Copy Markdown
Member

Hi @jefchien

Thank you for your contribution! Could you please explain to me a bit more why would we want to provide the SHA as an input rather than just using the one provided via pull request or fall back to the current commit's sha?

@jefchien

Copy link
Copy Markdown
Author

Hi @ktrz,

So, in my use case, the workflow where the action is used can be triggered by a workflow dispatch where the SHA is provided as an input. This allows us to run the benchmarking after successful CI workflow runs or on selected commits. The issue I've found is that the github.context.ref used in the fall back is the workflow commit SHA rather than the one actually used in the benchmarking. If there's another way to access the workflow dispatch inputs, it might be a better solution. This PR provides an optional field that will supersede any of the other attempts.

@NathanielRN

Copy link
Copy Markdown
Contributor

@jefchien

Is running the workflow_dispatch job event an automated process? Instead of providing the commit_sha as input, would you be able to push a branch or tag and run the workflow from there instead?

That way you can make the branch point to the commit you want, and run the workflow from that branch, so that the commit is correct and you don't need to provide the commit_sha as input.

It might be more tricky if your invocation of the workflow_dispatch job is automated (because you'd need a GitHub account to publish it from I guess) so that's why I ask.

@jefchien

jefchien commented Jan 6, 2022

Copy link
Copy Markdown
Author

@NathanielRN

Running the workflow_dispatch is a manual process, but the same workflow is also triggered by a repository_dispatch from a different workflow. That's an interesting workaround. I suppose I could use a GitHub action like https://github.com/marketplace/actions/create-branch to create the branch as part of the workflow and then checkout that branch in the job used to run this action. Actually, that probably won't work since the GitHub context is based on the workflow run.

@khanhntd

khanhntd commented Feb 1, 2023

Copy link
Copy Markdown

Hi @ktrz , any feedback though?

@ktrz

ktrz commented Feb 2, 2023

Copy link
Copy Markdown
Member

I'll get back to this during the weekend as I have a pretty busy week

@ktrz ktrz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR looks good. Just need some merge conflicts resolved. And please also include a test specific for your use-case

Comment thread test/write.spec.ts
externalDataJsonPath: undefined,
maxItemsInChart: null,
failThreshold: 2.0,
commitSha: 'dummy sha',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should add specific tests for the use-case where we set the explicit commitSha rather than just adding this param here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants